package com.kehutong.payfees.service.treasure;

//import com.kehutong.payfees.entity.treasure.PersonalAccount;
//import com.kehutong.payfees.util.ESignTreasureUrlConfig;
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.mvc.webservice.WebService;
//import org.coraframework.orm.Pool;
//import org.coraframework.orm.jdbc.SQLSession;
//
//@WebService("/sign/treasure/account")
//public class ESignTreasurePersonalAccountServiceImpl {
//
//    @Inject
//    protected SQLSession jdbcSession;
//
//    @Inject
//    private ESignTreasureOAuthServiceImpl eSignTreasureOAuthService;
//
//    @Inject
//    private ESignTreasureUrlConfig eSignTreasureUrlConfig;
//
//    public Object pagePersonalAccount(JSONObject jsonObject) {
//        return jdbcSession.findPage(PersonalAccount.class)
//                .eq(jsonObject, "name", "idNumber", "mobile")
//                .eq("deleted", false)
//                .page(jsonObject).exe();
//    }
//
//    public void createPersonalAccount(PersonalAccount personalAccount) throws Exception {
//        JSONObject jsonObject = eSignTreasureUrlConfig.postESignTreasure("/v1/accounts/createByThirdPartyUserId", (http) -> {
//            JSONObject bodyParams = setRequestBody(personalAccount);
//            bodyParams.put("thirdPartyUserId", personalAccount.getId());
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        personalAccount.setAccountId(jsonObject.getString("accountId"));
//        jdbcSession.insert(personalAccount);
//    }
//
//    public Object getPersonalAccount(String id) {
//        return Pool.get(PersonalAccount.class, id);
//    }
//
//    public void updatePersonalAccount(PersonalAccount personalAccount) throws Exception {
//        eSignTreasureUrlConfig.put("/v1/accounts/" + personalAccount.getAccountId(), (http) -> {
//            JSONObject bodyParams = setRequestBody(personalAccount);
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        jdbcSession.updateById(personalAccount);
//    }
//
//    public void deletePersonalAccount(String accountId) throws Exception {
//        eSignTreasureUrlConfig.delete("/v1/accounts/" + accountId, (http) -> {
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        PersonalAccount personalAccount = jdbcSession.findOne(PersonalAccount.class)
//                .eq("accountId", accountId)
//                .eq("delete", false).exe();
//        personalAccount.setDeleted(true);
//        jdbcSession.updateById(personalAccount);
//    }
//
//    private JSONObject setRequestBody(PersonalAccount personalAccount) {
//        JSONObject bodyParams = new JSONObject();
//
//        bodyParams.put("name", personalAccount.getName());
//        bodyParams.put("idType", personalAccount.getIdType());
//        bodyParams.put("idNumber", personalAccount.getIdNumber());
//        bodyParams.put("mobile", personalAccount.getMobile());
//        bodyParams.put("email", personalAccount.getEmail());
//
//        return bodyParams;
//    }
//}
